//
//  PlayListViewController.m
//  GSG
//
//  Created by dllo on 15/5/4.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "PlayListViewController.h"
#import"SongModel.h"
#import "SongBookCell.h"
#import "singleSong.h"
#import "PlayerViewController.h"

@interface PlayListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,retain)UITableView *tableview;
@property(nonatomic,retain)UILabel *label;
@property(nonatomic,copy)NSString *str;
@property(nonatomic,copy)NSString *documentPath;
@end

@implementation PlayListViewController
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{

    self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if(self){
            self.title = @"当前播放";
    }
    return self;
}
-(void)actionBuLand{
    PlayListViewController *plvc=[[PlayListViewController alloc]init];
    [self.navigationController pushViewController:plvc animated:YES];
    [plvc release];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bujing"]];
    
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"播放" style:UIBarButtonItemStyleDone target:self action:@selector(actionBuLand)];
    self.navigationItem.rightBarButtonItem.tintColor=[UIColor whiteColor];
    

    UIAlertView *alterView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"当前没有正在播放的列表" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [self.view addSubview:alterView];
    if([singleSong shareSingleSong].arrSong.count==0){
        [alterView show];}
    
    
    self.tableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height-self.view.frame.size.height * 100 / 667)];
    self.tableview.backgroundColor = [UIColor clearColor];
    self.tableview.rowHeight=100;
    [self.view addSubview: self.tableview ];
    self.tableview.delegate=self;
    self.tableview.dataSource=self;
    [_tableview release];
//    self.label=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 3, 0, self.view.frame.size.width/ 3, 60)];
//        NSArray *sandBoxPath=NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
//        NSString *sandPath=sandBoxPath[0];
//        self.documentPath=[sandPath stringByAppendingPathComponent:@"songname.txt"];
//    
//    self.str=[NSString stringWithContentsOfFile:self.documentPath encoding:NSUTF8StringEncoding error:nil];
//    
//    self.label.text=self.str;
//    self.label.tintColor=[UIColor whiteColor];
//    self.label.textAlignment=1;
//    self.label.font=[UIFont systemFontOfSize:20];
//    self.label.tintColor=[UIColor blackColor];
//    [self.view addSubview:self.label];
//    [self.label release];
    
    
    }
    

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([singleSong shareSingleSong].arrSong.count==0) {
        return 0;
    }
    else{
        return [singleSong shareSingleSong].arrSong.count;}
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *reuse=@"reuse";
    
    SongBookCell *cell=[tableView dequeueReusableCellWithIdentifier:reuse];
    if(!cell){
        
        cell=[[[SongBookCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
        
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor clearColor];
    SongModel *song=[singleSong shareSingleSong].arrSong[indexPath.row];
    NSString *str = [NSString stringWithFormat:@"%ld.%@",indexPath.row +1,song.song_name];
    
    cell. singer_nameLabel.text=song.singer_name;
    cell.song_nameLabel.text=str;
    
    
    
    
    return  cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

//    PlayerViewController*pvc=[[PlayerViewController alloc]init];
//
//    
//    pvc.arr= [singleSong shareSingleSong].arrSong;
//    pvc.num=indexPath.row;
//    [self.navigationController pushViewController:pvc animated:YES];
//    [pvc release];

    [singleSong shareSingleSong].num=indexPath.row;
    
    NSNotificationCenter *center=[NSNotificationCenter  defaultCenter];
    
    [center postNotificationName:@"播放" object:@"收到了看见了" userInfo:nil];
    

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
